module.exports = function override(config, env) {
    //console.log(JSON.stringify(config));
    const oneOfRule = config.module.rules.find(conf => !!conf.oneOf);
    const tsLoader = oneOfRule.oneOf.find(conf => {
        if (typeof(conf.loader) === "string" && conf.loader.includes('ts-loader')){
            return true;
        }

        if (conf.use instanceof Array) {
            const oneOfUse2 = conf.use.find(use=>typeof(use.loader) === "string" && use.loader.includes('ts-loader'));
            if (oneOfUse2) {
                return true;
            }
        }

        return false;
    });
    tsLoader.use = undefined;
    tsLoader.loader = require.resolve('awesome-typescript-loader');
    tsLoader.query = {
        useBabel: true,
    };

    const tsLintLoader = config.module.rules.find(conf => {
        return conf.loader && conf.loader.includes('tslint-loader')
    });
    if (tsLintLoader) {
        tsLintLoader.options = tsLintLoader.options || {};
        // FIXED Warning: The 'no-use-before-declare' rule requires type infomation.
        tsLintLoader.options.typeCheck = true;
    }

    const rewireLess = require('react-app-rewire-less');
    config = rewireLess(config, env);

    const path = require('path');
    // For import with absolute path
    config.resolve.modules = [path.resolve('src')].concat(config.resolve.modules)

    return config
};
